package com.ruoyi.system.service.impl;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.LabInstrumentationForeignServiceMapper;
import com.ruoyi.system.domain.LabInstrumentationForeignService;
import com.ruoyi.system.service.ILabInstrumentationForeignServiceService;

import javax.annotation.Resource;

/**
 * 仪器对外服务Service业务层处理
 * 
 * @author lzlong
 * @date 2022-04-29
 */
@Service
public class LabInstrumentationForeignServiceServiceImpl implements ILabInstrumentationForeignServiceService 
{
    @Resource
    private LabInstrumentationForeignServiceMapper labInstrumentationForeignServiceMapper;

    /**
     * 查询仪器对外服务
     * 
     * @param id 仪器对外服务ID
     * @return 仪器对外服务
     */
    @Override
    public LabInstrumentationForeignService selectLabInstrumentationForeignServiceById(Long id)
    {
        return labInstrumentationForeignServiceMapper.selectLabInstrumentationForeignServiceById(id);
    }

    /**
     * 查询仪器对外服务列表
     * 
     * @param labInstrumentationForeignService 仪器对外服务
     * @return 仪器对外服务
     */
    @Override
    public List<LabInstrumentationForeignService> selectLabInstrumentationForeignServiceList(LabInstrumentationForeignService labInstrumentationForeignService)
    {
        List<LabInstrumentationForeignService> list = labInstrumentationForeignServiceMapper.selectLabInstrumentationForeignServiceList(labInstrumentationForeignService);
        return list;
    }

    /**
     * 新增仪器对外服务
     * 
     * @param labInstrumentationForeignService 仪器对外服务
     * @return 结果
     */
    @Override
    public int insertLabInstrumentationForeignService(LabInstrumentationForeignService labInstrumentationForeignService)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        DateTime dateTime = DateUtil.offsetMonth(labInstrumentationForeignService.getServicePeriodStart(), 1);
        labInstrumentationForeignService.setServicePeriodStart(dateTime);
        DateTime endDate = DateUtil.offsetMonth(labInstrumentationForeignService.getServicePeriodEnd(), 1);
        labInstrumentationForeignService.setServicePeriodEnd(endDate);
        labInstrumentationForeignService.setCreatedTime(new Date());
        labInstrumentationForeignService.setCreatedBy(loginUser.getUsername());
        return labInstrumentationForeignServiceMapper.insertLabInstrumentationForeignService(labInstrumentationForeignService);
    }

    /**
     * 修改仪器对外服务
     * 
     * @param labInstrumentationForeignService 仪器对外服务
     * @return 结果
     */
    @Override
    public int updateLabInstrumentationForeignService(LabInstrumentationForeignService labInstrumentationForeignService)
    {
        DateTime dateTime = DateUtil.offsetMonth(labInstrumentationForeignService.getServicePeriodStart(), 1);
        labInstrumentationForeignService.setServicePeriodStart(dateTime);
        DateTime endDate = DateUtil.offsetMonth(labInstrumentationForeignService.getServicePeriodEnd(), 1);
        labInstrumentationForeignService.setServicePeriodEnd(endDate);
        return labInstrumentationForeignServiceMapper.updateLabInstrumentationForeignService(labInstrumentationForeignService);
    }

    /**
     * 批量删除仪器对外服务
     * 
     * @param ids 需要删除的仪器对外服务ID
     * @return 结果
     */
    @Override
    public int deleteLabInstrumentationForeignServiceByIds(Long[] ids)
    {
        return labInstrumentationForeignServiceMapper.deleteLabInstrumentationForeignServiceByIds(ids);
    }

    /**
     * 删除仪器对外服务信息
     * 
     * @param id 仪器对外服务ID
     * @return 结果
     */
    @Override
    public int deleteLabInstrumentationForeignServiceById(Long id)
    {
        return labInstrumentationForeignServiceMapper.deleteLabInstrumentationForeignServiceById(id);
    }
}
